package com.yhc.order.server.controller;

import com.yhc.common.dto.BaseResult;
import com.yhc.common.util.ResultUtil;
import com.yhc.order.api.OrderApi;
import com.yhc.order.api.request.OrderSaveRequest;
import com.yhc.order.api.response.OrderSaveResponse;
import com.yhc.order.server.service.IOrderService;
import io.seata.core.context.RootContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class OrderController implements OrderApi {

    @Autowired
    IOrderService orderService;


    @Override
    public BaseResult<OrderSaveResponse> save(OrderSaveRequest request) {

        log.info("# seata xid:{}", RootContext.getXID());

        Long recordId = orderService.save(request.getAmount());
        OrderSaveResponse response = OrderSaveResponse.builder().orderId(recordId).build();
        return ResultUtil.ok(response);
    }
}
